const request = require('./request')
const config = require('../../config')

class WCS {

	constructor() {
		this.host = config.wcs.host
	}

	/**
	 * notice
	 */
	async notice(data) {
		
		try {
			const url = `${this.host}/wcs/restful/api/v3/system_car/feedbackTask`
			
			const response = await request.post(url, data)

			if (response.data.responseCode !== 0) {
				logger.error('通知WCS事件Restful调用返回结果失败')
				logger.info(response.data)

			}
		}
		catch (error) {
			
			logger.error('通知WCS事件Restful调用失败')
			logger.info(error)
		}
	}

	async cancelTask(data) {
		try {
			const url = `${this.host}/wcs/restful/api/v3/system_car/deprecateTask`
			const response = await request.post(url, data)

			if (response.data.responseCode !== 0) {
				logger.error('通知WCS事件Restful调用返回结果失败')
				logger.info(response.data)
			}
		}
		catch (error) {
			logger.error('通知WCS取消任务事件Restful调用失败')
			logger.info(error)
		}
	}
}

module.exports = new WCS()